package com.jiangyg.mall.db.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 类描述：路由数据源类
 * 
 * @author jiangyg
 * @date 2020-10-17
 * @version 2.0
 */
public class RoutingDataSource extends AbstractRoutingDataSource {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(RoutingDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        final String ds = DataSourceContextHolder.current();
        if (logger.isDebugEnabled()) {
            logger.debug("当前线程[{}]数据源为[{}]", Thread.currentThread().getName(), ds);
        }
        return ds;
    }

}
